//
//  LoginUnit.m
//  Dodoru
//
//  Created by zengyuan on 6/25/14.
//  Copyright (c) 2014 zengyuan. All rights reserved.
//

#import "UserUnit.h"

#define LOGIN_MEASSGE @"LOGIN_MEASSGE"

@implementation UserUnit
-(void)encodeWithCoder:(NSCoder *)encoder
{
    [encoder encodeObject:self.userName forKey:@"userName"];
    [encoder encodeObject:self.userPasswd forKey:@"userPasswd"];
    [encoder encodeObject:self.userPhone forKey:@"userPhone"];
    [encoder encodeObject:self.useruuid forKey:@"useruuid"];
    [encoder encodeObject:self.headImgUrl forKey:@"headImgUrl"];
 

}

-(id)initWithCoder:(NSCoder *)decoder
{
    self.userName = [decoder decodeObjectForKey:@"userName"];
    self.userPasswd = [decoder decodeObjectForKey:@"userPasswd"];
    self.userPhone = [decoder decodeObjectForKey:@"userPhone"];
    self.useruuid = [decoder decodeObjectForKey:@"useruuid"];
    self.headImgUrl = [decoder decodeObjectForKey:@"headImgUrl"];
    
    return self;
}

+(BOOL)resetLoginUnit:(UserUnit *)_loginunit{
    if (!_loginunit)
    {
        return NO;
    }
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSData *_data = [NSKeyedArchiver archivedDataWithRootObject:_loginunit];
    [defaults setObject:_data forKey:LOGIN_MEASSGE];
    
    return YES;
}

+(UserUnit *)getActiveUser
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSData *wdata = [defaults objectForKey:LOGIN_MEASSGE];
    UserUnit *userunit = [NSKeyedUnarchiver unarchiveObjectWithData:wdata];
    return userunit;
    
}

+(void)removeActiveUser{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults removeObjectForKey:LOGIN_MEASSGE];
}

@end
